import router from "./router";
import store from "./store";

// import { getToken } from '@/utils/auth'
// import { isRelogin } from '@/utils/request'

const whiteList = ["/login"];

router.beforeEach((to, from, next) => {
  console.log("1111to", to);

  if (to.path === "/login") {
    next();
  } else {
    const name = sessionStorage.getItem("name");
    const password = sessionStorage.getItem("password");

    if (name && password) {
      // isRelogin.show = true;
      // // 判断当前用户是否已拉取完user_info信息
      // store
      //   .dispatch("GetInfo")
      //   .then(() => {
      //     isRelogin.show = false;
      //     store.dispatch("GenerateRoutes").then((accessRoutes) => {
      //       // 根据roles权限生成可访问的路由表
      //       router.addRoutes(accessRoutes); // 动态添加可访问路由表
      //       next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
      //     });
      //   })
      //   .catch((err) => {
      //     store.dispatch("LogOut").then(() => {
      //       next({ path: "/" });
      //     });
      // });
      next();
    } else {
      next({ path: "/login" });
    }
  }
});

router.afterEach(() => {});
